//
//  HNSH_XJDROtherCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/6/15.
//

#import "HNSH_XJDROtherCell.h"

@interface HNSH_XJDROtherCell ()

/* bgView */
@property (nonatomic, strong) UIView *bgView;
/* titleLabel */
@property (nonatomic, strong) UILabel *titleLabel;
/* desLabel */
@property (nonatomic, strong) UILabel *desLabel;
/* button */
@property (nonatomic, strong) UIButton *button;
/* lineView */
@property (nonatomic, strong) UIView *lineView;

@end

@implementation HNSH_XJDROtherCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        self.backgroundColor = [UIColor whiteColor];
        [self configView];
    }
    return self;
}

- (void)setModel:(HNSH_XJDROtherItemModel *)model {
    _model = model;
    self.titleLabel.text = model.name;
    self.desLabel.text = model.amount_txt;
    
    self.button.hidden = model.status == 2;
    self.button.backgroundColor = model.status == 0 ? [UIColor appGreenColor] : [UIColor colorWithHexString:@"#D4C5C5"];
    [self.button setTitle:model.status == 0 ? @"未激活" : @"已激活" forState:UIControlStateNormal];
}

- (void)configView {
    [self.contentView addSubview:self.bgView];
    [self.bgView addSubview:self.titleLabel];
    [self.bgView addSubview:self.desLabel];
    [self.bgView addSubview:self.button];
    [self.bgView addSubview:self.lineView];
}

#pragma mark lazy
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc]initWithFrame:CGRectMake(16, 0, kScreenWidth-32, 72)];
        _bgView.backgroundColor = [UIColor colorWithHexString:@"#F8F8F8"];
    }
    return _bgView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 15, 200, 20)];
        _titleLabel.text = @"激活一星收益";
        _titleLabel.textColor = [UIColor appBlackLabelColor];
        _titleLabel.font = [UIFont boldSystemFontOfSize:14];
    }
    return _titleLabel;
}

- (UILabel *)desLabel {
    if (!_desLabel) {
        _desLabel = [[UILabel alloc]initWithFrame:CGRectMake(16, 39, 200, 17)];
        _desLabel.text = @"需10.00绿色能量";
        _desLabel.textColor = [UIColor appGrayLabelColor];
        _desLabel.font = [UIFont systemFontOfSize:12];
    }
    return _desLabel;
}

- (UIButton *)button {
    if (!_button) {
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.frame = CGRectMake(self.bgView.width-86, 20, 70, 32);
        [_button setTitle:@"去激活" forState:UIControlStateNormal];
        [_button setTitleColor:[UIColor appWhiteLabelColor] forState:UIControlStateNormal];
        _button.titleLabel.font = [UIFont boldSystemFontOfSize:14];
        _button.backgroundColor = [UIColor appGreenColor];
        _button.layer.cornerRadius = 16.0f;
        _button.layer.masksToBounds = YES;
        WeakSelf(weakSelf);
        [[_button rac_signalForControlEvents:UIControlEventTouchUpInside] subscribeNext:^(__kindof UIControl * _Nullable x) {
            if (weakSelf.model.status == 1) {
                [kSTWindow makeToast:@"已激活"];
            } else {
                if (weakSelf.buttonBlock) {
                    weakSelf.buttonBlock(weakSelf.model);
                }
            }
        }];
    }
    return _button;
}

- (UIView *)lineView {
    if(!_lineView) {
        _lineView = [[UIView alloc]initWithFrame:CGRectMake(16, 71.5, self.bgView.width-32, 0.5)];
        _lineView.backgroundColor = [UIColor colorWithHexString:@"#E3E3E3"];
    }
    return _lineView;
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
